﻿using Alison.EFCore.Dto;
using Alison.Tools.HttpContact.Response;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Alison.API.Controllers
{
	/// <summary>
	/// 获取Token
	/// </summary>
	[Route("api/[controller]")]
	[ApiController]
	public class AuthenticationController : ControllerBase
	{

		private readonly IAuthenticateService _authService;
		public AuthenticationController(IAuthenticateService authService) {
			_authService = authService;
		}


		/// <summary>
		/// 获取ToKen
		/// </summary>
		/// <param name="request"></param>
		/// <returns></returns>
		[AllowAnonymous]
		[HttpPost, Route("requestToken")]
		public ActionResult RequestToken([FromBody] LoginDTO request) {
			if (!ModelState.IsValid) return BadRequest("Invalid Request");

			ApiResponse token;
			_authService.IsAuthenticated(request, out token);

			if (token.StatusCode == 200) {
				 
				return Ok(token);
			}
			return BadRequest(token);
		} 
	}
}
